package com.wehealth.three.lib_common.ui.component

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

abstract class BaseBottomDialog<T : ViewDataBinding> : AppCompatDialogFragment() {
    var dataBinding: T? = null

    abstract fun getLayoutId(): Int

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val window = dialog?.window
        dataBinding = DataBindingUtil.inflate(
            inflater,
            getLayoutId(),
            window?.findViewById(android.R.id.content),
            false
        )
        initBinding(inflater)
        window?.setBackgroundDrawable(setDialogBackground())
        window?.setLayout(
            widthLayoutManager(),
            heightLayoutManager()
        )
        window?.setGravity(setGravity())
        return dataBinding!!.root
    }


    fun setDialogBackground(colorDrawable: ColorDrawable = ColorDrawable(Color.TRANSPARENT)): ColorDrawable {
        return colorDrawable
    }

    abstract fun widthLayoutManager(): Int
    abstract fun heightLayoutManager(): Int

    abstract fun setGravity(): Int

    abstract fun initBinding(inflater: LayoutInflater)
}